/*
 * @Author: 三岁小仙仙 scitctocdtu@qq.com
 * @Date: 2024-10-01 20:33:28
 * @LastEditors: 三岁小仙仙 scitctocdtu@qq.com
 * @LastEditTime: 2024-10-05 14:40:25
 * @FilePath: \demo\vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import path from "path"
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import Components from "unplugin-vue-components/vite"
import { VantResolver } from "unplugin-vue-components/resolvers"
import postcssPxToViewport from "postcss-px-to-viewport-8-plugin"
import legacy from "@vitejs/plugin-legacy"

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		Components({
			resolvers: [VantResolver()],
		}),
		// 谷歌浏览器需大于64版本，  不适用IE等！
		legacy({
			targets: ["chrome>=64", "not IE 11"],
		}),
	],
	base: "./",
	css: {
		preprocessorOptions: {
			scss: {
				// 在每个SCSS文件编译前自动注入以下内容
				additionalData: `@import "./src/assets/scss/iframe.scss";`,
			},
		},
		postcss: {
			plugins: [
				postcssPxToViewport({
					unitToConvert: "px", // 要转化的单位
					viewportWidth: 375, // UI设计稿的宽度
					unitPrecision: 5, // 转换后的精度，即小数点位数
				}),
			],
		},
	},
	build: {
		chunkSizeWarningLimit: 1600,
	},
	resolve: {
		alias: [
			{ find: "@", replacement: path.resolve(__dirname, "src") },
			{
				find: "@pages",
				replacement: path.resolve(__dirname, "src/pages"),
			},
			{
				find: "@hooks",
				replacement: path.resolve(__dirname, "src/hooks"),
			},
			{
				find: "@store",
				replacement: path.resolve(__dirname, "src/store"),
			},
			{
				find: "@common",
				replacement: path.resolve(__dirname, "src/common"),
			},
			{ find: "@lang", replacement: path.resolve(__dirname, "src/lang") },
			{
				find: "@components",
				replacement: path.resolve(__dirname, "src/components"),
			},
			{
				find: "@utility",
				replacement: path.resolve(__dirname, "src/utility"),
			},
		],
	},
})
